package com.lanou.controller;

import com.lanou.bean.BankInfo;
import com.lanou.bean.VipInfo;
import com.lanou.service.BankInfoService;
import com.lanou.service.VipInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("bank")
public class BankController {

    @Autowired
    private BankInfoService bankInfoService;

    @Autowired
    private VipInfoService vipInfoService;
    /**
     * 根据会员id查询拥有的银行卡信息
     * @return
     */
    @RequestMapping("/getBankInfoByVipId.do")
    @ResponseBody
    public List<BankInfo> getBankInfoByVipId(Integer id){
        System.out.println("接收到的信息------"+id);
        //根据会员id查询银行卡信息
        //根据会员id查询会员账号vip_no
        String vipNo = vipInfoService.selectVipNoById(id);
        System.out.println("查询到的会员账号信息----"+vipNo);
        //在银行卡信息表中根据会员账号查询银行卡信息
        List<BankInfo> bankInfoList = bankInfoService.selectBankInfoListByVipNo(vipNo);
        System.out.println("查询银行卡信息------"+bankInfoList);
        return bankInfoList;
    }
    /**
     * 根据id查询会员信息
     * @return
     */
    @RequestMapping("/getVipInfoAccountByVipId.do")
    @ResponseBody
    public VipInfo getVipInfoAccountByVipId(Integer id){
        VipInfo vipInfo = bankInfoService.getVipInfoAccountByVipId(id);
        System.out.println("获取用户名-----"+vipInfo);
        return vipInfo;
    }

    /**
     *  根据会员账号添加银行卡信息
     * @return
     */
    @RequestMapping("/addBankInfo.do")
    @ResponseBody
    public Map<String, Object> addBankInfo(@RequestParam Map<String,Object> map){
        System.out.println("接收到的银行卡信息-------"+map);
        BankInfo bankInfo=new BankInfo();
        bankInfo.setVipNo((String) map.get("vipNo"));
        bankInfo.setBankCardNo((String) map.get("bankCardNo"));
        bankInfo.setBankName((String) map.get("bankName"));
        bankInfo.setBankAddr("平顶三啊啊");
        bankInfo.setIsUsed("y");
        bankInfo.setInstDate(new Date());
        bankInfo.setInstId(1);
        bankInfo.setBankType((String) map.get("bankCardType"));
        //执行插入的操作
        int result = bankInfoService.insertSelective(bankInfo);
        Map<String,Object> map1=new HashMap<>();
        if(result>0){
            map1.put("result","success");
            return map1;
        }else {
            map1.put("result","false");
            return map1;
        }
    }


}
